<?php

namespace App\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

/**
 * 岗位时间点设置控制器
 *
 * Date: 16/05/2018
 * @author George
 * @package App\Http\Controllers
 */
class TimingController extends Controller
{
	/**
	 * 删除岗位设置
	 *
	 * Date: 16/05/2018
	 * @author George
	 * @param Request $request
	 * @return \Illuminate\Http\JsonResponse
	 */
	public function destroy(Request $request)
	{
		$this->validate($request, [
			'genre_id' => 'required',
			'station_id' => 'required',
		]);

		$genre_id = $request->get('genre_id');
		$station_id = $request->get('station_id');

		if ($station_id && $genre_id) {
			try {
				DB::table('timings')
					->where('station_id', $station_id)
					->where('genre_id', $genre_id)->delete();
			} catch (Exception $exception) {
				Log::error($exception->getMessage());
				return internalError('删除岗位设置失败');
			}
		}

		return deleted();
	}
}
